package com.campus.controller;

import com.campus.common.ResponseResult;
import com.campus.model.Evaluation;
import com.campus.service.EvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @desc: 评价控制器类，用于处理评价相关的HTTP请求
 * @author: hjm
 * @date: 2024/11/22 14.41
 */
@RequestMapping("/evaluation")
@RestController
public class EvaluationController {
    @Autowired
    private EvaluationService evaluationService;

    /**
     * 添加评价
     *
     * @param evaluation 评价对象
     * @return 添加结果
     */
    @PostMapping("/add")
    public ResponseResult addEvaluation(@RequestBody Evaluation evaluation) {
        Integer result = evaluationService.addEvaluation(evaluation);
        if (result == null || result == 0) {
            return ResponseResult.error(HttpStatus.BAD_REQUEST, "添加评价失败");
        } else {
            return ResponseResult.ok(evaluation, "添加评价成功");
        }
    }
}